//
//  UIViewController+YTNavBarController.m
//  yitaicaijing
//
//  Created by DIANGHONG on 2018/7/12.
//  Copyright © 2018年 DIANGHONG. All rights reserved.
//

#import "UIViewController+YTNavBarController.h"
#import <objc/runtime.h>
@implementation UIViewController (YTNavBarController)



- (void)setNavBarHairlineImageView:(UIImageView *)navBarHairlineImageView
{
    objc_setAssociatedObject(self, @selector(navBarHairlineImageView), navBarHairlineImageView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
}

- (UIImageView *)navBarHairlineImageView
{
    return objc_getAssociatedObject(self, @selector(findHairlineImageViewUnder:));
}


- (UIImageView *)findHairlineImageViewUnder:(UIView *)view
{
    if ([view isKindOfClass:UIImageView.class] && view.bounds.size.height <= 1.0) {
        return (UIImageView *)view;
    }
    for (UIView *subview in view.subviews) {
        UIImageView *imageView = [self findHairlineImageViewUnder:subview];
        if (imageView) {
            return imageView;
        }
    }
    return nil;
}

+(BOOL)isCurrentViewControllerVisible:(UIViewController *)viewController
{
    return (viewController.isViewLoaded && viewController.view.window);
}

@end
